package com.bruce.starts.demo.thread.producer;

import com.google.common.collect.Lists;

import java.util.List;

public class Consumer implements Runnable{
    private List<String> list = Lists.newArrayList();

    public Consumer(List<String> list) {
        this.list = list;
    }

    @Override
    public void run() {
        while (true){
            synchronized (list){
                if(list.size()==0){
                    try {
                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    list.remove(0);
                    System.out.println("消费者：仓库剩余数量"+list.size());
                }
                list.notifyAll();
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
